#!/bin/bash

if [ ! -d RV64 ]; then
  echo Run build from the coq directory
  exit 1
fi

if [ -v BBV_DIR ]; then
  BBV_OPT=-Q "$BBV_DIR"
fi

set -ex
cd lib/sail
make
cd ../../RV32
coqc $BBV_OPT -Q ../lib/sail Sail riscv_extras.v
coqc $BBV_OPT -Q ../lib/sail Sail mem_metadata.v
coqc $BBV_OPT -Q ../lib/sail Sail riscv_types.v
coqc $BBV_OPT -Q ../lib/sail Sail riscv.v
cd ../RV64
coqc $BBV_OPT -Q ../lib/sail Sail riscv_extras.v
coqc $BBV_OPT -Q ../lib/sail Sail mem_metadata.v
coqc $BBV_OPT -Q ../lib/sail Sail riscv_types.v
coqc $BBV_OPT -Q ../lib/sail Sail riscv.v
cd ../duopod
coqc $BBV_OPT -Q ../lib/sail Sail riscv_extras.v
coqc $BBV_OPT -Q ../lib/sail Sail mem_metadata.v
coqc $BBV_OPT -Q ../lib/sail Sail riscv_duopod_types.v
coqc $BBV_OPT -Q ../lib/sail Sail riscv_duopod.v
